﻿package com.view
{
	import com.controller.OverStartupCommand;
	import com.model.PicListProxy;
	import com.model.vo.PicVo;
	
	import mx.controls.Image;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class WheelPicMediator extends Mediator implements IMediator
	{
		public static const NAME:String="wheelPicMediator_name";
		public function WheelPicMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
		}
		override public function  listNotificationInterests():Array{
			return [OverStartupCommand.DATACOMPLETE,NumMediator.CHANGEPIC]
		}
		override public function handleNotification(notification:INotification):void{
			var name:String=notification.getName();
			switch(name){
				case OverStartupCommand.DATACOMPLETE:
					var currentNum:int=facade.retrieveProxy(PicListProxy.NAME).getData().currentNum;
					var list:Array=facade.retrieveProxy(PicListProxy.NAME).getData().list;
					showPic(list[currentNum] as PicVo);
					break;
				case NumMediator.CHANGEPIC:
					var num:int=notification.getBody() as int;
					var list2:Array=facade.retrieveProxy(PicListProxy.NAME).getData().list;
					showPic(list2[num] as PicVo);
					break;
			}
		}
		private function showPic(picVo:PicVo):void{
			var app:WheelPic = viewComponent as WheelPic;
			
			if(app.emptyMc.numElements){
				app.emptyMc.removeAllElements();
			}
			
			var image:Image=new Image();
			image.source=picVo.url;
			image.width=500;
			image.height=380;
			app.emptyMc.addElement(image);
		}
	}
}